package com.wangxl.rabbitmqdemo.producer;

import com.wangxl.rabbitmqdemo.dto.BasicMessageInput;
import com.wangxl.rabbitmqdemo.enumtype.RoutingKeyEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author: wangxl
 * @Date: 2019/3/23 14:19
 */
@Component
@Slf4j
public class BusinessMessageSender {

    @Resource
    RabbitTemplate rabbitTemplate;

    public void sendBusinessMessage(BasicMessageInput<String> messageInput){

        String uuid = UUID.randomUUID().toString();
        log.info("send business message---uuid---{}",uuid);
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(uuid);
        rabbitTemplate.convertAndSend("businessExchange", RoutingKeyEnum.MESSAGE.getRoutingKey(), messageInput, correlationData);

    }

    public void sendBusinessEmail(BasicMessageInput<String> emailInput){

        String uuid = UUID.randomUUID().toString();
        log.info("send business email---uuid---{}",uuid);
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(uuid);
        rabbitTemplate.convertAndSend("businessExchange", RoutingKeyEnum.EMAIL.getRoutingKey(), emailInput, correlationData);

    }
}
